package com.photo.filter;

import top.hserver.core.interfaces.FilterAdapter;
import top.hserver.core.interfaces.HttpRequest;
import top.hserver.core.ioc.annotation.Bean;
import top.hserver.core.server.context.Webkit;

/**
 * @author hxm
 */
@Bean
public class AuthFilter implements FilterAdapter {

    @Override
    public void doFilter(Webkit webkit) throws Exception {
        HttpRequest request = webkit.httpRequest;
        if (request.getUri().contains("css") || request.getUri().contains("js")) {
            return;
        }
        String auth = request.getHeader("cookie");
        if (auth == null || !auth.contains("auth=969")) {
            webkit.httpResponse.sendTemplate("/login.ftl");
        }
    }
}
